class ListplansController < ApplicationController
     before_filter(:get_plan)

  def create
    # Create a comment object that has
    # been instantiated with attributes
    # and linked to the post object
    @listplan = @plan.listplans.build(params[:listplan])
    if @listplan.save
      flash[:notice] = 'Listplan was successfully created.'
      respond_to do |format|
        format.html { redirect_to plan_url(@plan) }
        format.xml  { render :xml => @listplan,
          :status => :created, :location => @plan }
      end
    else
      flash[:notice] = 'Comment was not created.'
      respond_to do |format|
        format.html { redirect_to plan_url(@plan) }
        format.xml  { render :xml => @listplan.errors,
          :status => :unprocessable_entity }
      end
    end
  end

    def update
    @listplan = Listplan.find(params[:id])
    respond_to do |format|
      if @listplan.update_attributes(params[:listplan])
        flash[:notice] = 'Post was successfully updated.'
        format.html { redirect_to(@plan) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @plan.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /posts/1
  # DELETE /posts/1.xml
  def destroy
    @listplan = Listplan.find(params[:id])
    @post.destroy

    respond_to do |format|
      format.html { redirect_to(plans_url) }
      format.xml  { head :ok }
    end
  end



private

  def get_plan
     @plan = Plan.find(params[:plan_id])
  end

end
